<!doctype html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Linux命令," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.1" />






<meta name="description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;chmod命令用于改变linux系统文件或目录的访问权限。用它控制文件或目录的访问权限。该命令有两种用法。一种是包含字母和操作符表达式的文字设定法；另一种是包含数字的数字设定法。 &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;Linux系统中的每个文件和">
<meta name="keywords" content="Linux命令">
<meta property="og:type" content="article">
<meta property="og:title" content="Linux 命令- chmod">
<meta property="og:url" content="https://hcldirgit.github.io/2017/09/03/2. Linux 命令/27. Linux 命令- chmod/index.html">
<meta property="og:site_name" content="失落的乐章">
<meta property="og:description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;chmod命令用于改变linux系统文件或目录的访问权限。用它控制文件或目录的访问权限。该命令有两种用法。一种是包含字母和操作符表达式的文字设定法；另一种是包含数字的数字设定法。 &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;Linux系统中的每个文件和">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2017-09-01T08:34:42.907Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Linux 命令- chmod">
<meta name="twitter:description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;chmod命令用于改变linux系统文件或目录的访问权限。用它控制文件或目录的访问权限。该命令有两种用法。一种是包含字母和操作符表达式的文字设定法；另一种是包含数字的数字设定法。 &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;Linux系统中的每个文件和">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://hcldirgit.github.io/2017/09/03/2. Linux 命令/27. Linux 命令- chmod/"/>





  <title>Linux 命令- chmod | 失落的乐章</title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  




<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  ga('create', '85*****1', 'auto');
  ga('send', 'pageview');
</script>


  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?87980c**************99ec5e26fb5";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>











  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">失落的乐章</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">技术面前，永远都是学生。</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-message">
          <a href="/message" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-external-link"></i> <br />
            
            留言
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="https://hcldirgit.github.io/2017/09/03/2. Linux 命令/27. Linux 命令- chmod/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="失落的乐章">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/0.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="失落的乐章">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Linux 命令- chmod</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-03T01:57:34+08:00">
                2017-09-03
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;chmod命令用于改变linux系统文件或目录的访问权限。用它控制文件或目录的访问权限。该命令有两种用法。一种是包含字母和操作符表达式的文字设定法；另一种是包含数字的数字设定法。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Linux系统中的每个文件和目录都有访问许可权限，用它来确定谁可以通过何种方式对文件和目录进行访问和操作。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;文件或目录的访问权限分为只读，只写和可执行三种。以文件为例，只读权限表示只允许读其内容，而禁止对其做任何的更改操作。可执行权限表示允许将该文件作为一个程序执行。文件被创建时，文件所有者自动拥有对该文件的读、写和可执行权限，以便于对文件的阅读和修改。用户也可根据需要把访问权限设置为需要的任何组合。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;有三种不同类型的用户可对文件或目录进行访问：文件所有者，同组用户、其他用户。所有者一般是文件的创建者。所有者可以允许同组用户有权访问文件，还可以将文件的访问权限赋予系统中的其他用户。在这种情况下，系统中每一位用户都能访问该用户拥有的文件或目录。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;每一文件或目录的访问权限都有三组，每组用三位表示，分别为文件属主的读、写和执行权限；与属主同组的用户的读、写和执行权限；系统中其他用户的读、写和执行权限。当用ls -l命令显示文件或目录的详细信息时，最左边的一列为文件的访问权限。 例如：</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ls -al</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll -al</span></div><div class="line">总计 316lrwxrwxrwx 1 root root     11 11-22 06:58 linklog.log -&gt; log2012.log</div><div class="line">-rw-r--r-- 1 root root 302108 11-13 06:03 log2012.log</div><div class="line">-rw-r--r-- 1 root root     61 11-13 06:03 log2013.log</div><div class="line">-rw-r--r-- 1 root root      0 11-13 06:03 log2014.log</div><div class="line">-rw-r--r-- 1 root root      0 11-13 06:06 log2015.log</div><div class="line">-rw-r--r-- 1 root root      0 11-16 14:41 log2016.log</div><div class="line">-rw-r--r-- 1 root root      0 11-16 14:43 log2017.log</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;以log2012.log为例：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">-rw-r--r-- 1 root root 296K 11-13 06:03 log2012.log</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;第一列共有10个位置，第一个字符指定了文件类型。在通常意义上，一个目录也是一个文件。如果第一个字符是横线，表示是一个非目录的文件。如果是d，表示是一个目录。从第二个字符开始到第十个共9个字符，3个字符一组，分别表示了3组用户对文件或者目录的权限。权限字符用横线代表空许可，r代表只读，w代表写，x代表可执行。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>例如：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">- rw- r-- r--</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;表示log2012.log是一个普通文件；log2012.log的属主有读写权限；与log2012.log属主同组的用户只有读权限；其他用户也只有读权限。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;确定了一个文件的访问权限后，用户可以利用Linux系统提供的chmod命令来重新设定不同的访问权限。也可以利用chown命令来更改某个文件或目录的所有者。利用chgrp命令来更改某个文件或目录的用户组。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;chmod命令是非常重要的，用于改变文件或目录的访问权限。用户用它控制文件或目录的访问权限。chmod命令详细情况如下。</p>
<h2 id="1-命令格式"><a href="#1-命令格式" class="headerlink" title="1.命令格式"></a>1.命令格式</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">chmod [-cfvR] [--<span class="built_in">help</span>] [--version] mode file</div></pre></td></tr></table></figure>
<h2 id="2-命令功能"><a href="#2-命令功能" class="headerlink" title="2.命令功能"></a>2.命令功能</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;用于改变文件或目录的访问权限，用它控制文件或目录的访问权限。</p>
<h2 id="3-命令参数"><a href="#3-命令参数" class="headerlink" title="3.命令参数"></a>3.命令参数</h2><h3 id="必要参数"><a href="#必要参数" class="headerlink" title="必要参数"></a>必要参数</h3><ul>
<li>-c 当发生改变时，报告处理信息</li>
<li>-f 错误信息不输出</li>
<li>-R 处理指定目录以及其子目录下的所有文件</li>
<li>-v 运行时显示详细处理信息</li>
</ul>
<h3 id="选择参数"><a href="#选择参数" class="headerlink" title="选择参数"></a>选择参数</h3><ul>
<li>–reference=&lt;目录或者文件&gt; 设置成具有指定目录或者文件具有相同的权限</li>
<li>–version 显示版本信息</li>
<li>&lt;权限范围&gt;+&lt;权限设置&gt; 使权限范围内的目录或者文件具有指定的权限</li>
<li>&lt;权限范围&gt;-&lt;权限设置&gt; 删除权限范围的目录或者文件的指定权限</li>
<li>&lt;权限范围&gt;=&lt;权限设置&gt; 设置权限范围内的目录或者文件的权限为指定的值</li>
</ul>
<h4 id="权限范围"><a href="#权限范围" class="headerlink" title="权限范围"></a>权限范围</h4><ul>
<li>u ：目录或者文件的当前的用户</li>
<li>g ：目录或者文件的当前的群组</li>
<li>o ：除了目录或者文件的当前用户或群组之外的用户或者群组</li>
<li>a ：所有的用户及群组</li>
</ul>
<h4 id="权限代号"><a href="#权限代号" class="headerlink" title="权限代号"></a>权限代号</h4><ul>
<li>r ：读权限，用数字4表示</li>
<li>w ：写权限，用数字2表示</li>
<li>x ：执行权限，用数字1表示</li>
<li><ul>
<li>：删除权限，用数字0表示</li>
</ul>
</li>
<li>s ：特殊权限 </li>
<li>该命令有两种用法。一种是包含字母和操作符表达式的文字设定法；另一种是包含数字的数字设定法。</li>
</ul>
<h5 id="文字设定法"><a href="#文字设定法" class="headerlink" title="文字设定法"></a>文字设定法</h5><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">chmod [who] [+|-|=] [mode] [filename]</div></pre></td></tr></table></figure>
<h5 id="数字设定法"><a href="#数字设定法" class="headerlink" title="数字设定法"></a>数字设定法</h5><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;我们必须首先了解用数字表示的属性的含义：0表示没有权限，1表示可执行权限，2表示可写权限，4表示可读权限，然后将其相加。所以数字属性的格式应为3个从0到7的八进制数，其顺序是（u）（g）（o）。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;例如，如果想让某个文件的属主有“读/写”二种权限，需要把4（可读）+2（可写）＝6（读/写）。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;数字设定法的一般形式为：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">chmod [mode] [filename]</div></pre></td></tr></table></figure>
<h6 id="数字与字符对应关系如下"><a href="#数字与字符对应关系如下" class="headerlink" title="数字与字符对应关系如下"></a>数字与字符对应关系如下</h6><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;r=4，w=2，x=1</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;若要rwx属性则4+2+1=7</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;若要rw-属性则4+2=6；</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;若要r-x属性则4+1=7。 </p>
<h2 id="4-使用实例"><a href="#4-使用实例" class="headerlink" title="4.使用实例"></a>4.使用实例</h2><h3 id="实例1：增加文件所有用户组可执行权限"><a href="#实例1：增加文件所有用户组可执行权限" class="headerlink" title="实例1：增加文件所有用户组可执行权限"></a>实例1：增加文件所有用户组可执行权限</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">chmod a+x log2012.log</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ls -al log2012.log </span></div><div class="line">-rw-r--r-- 1 root root 302108 11-13 06:03 log2012.log</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># chmod a+x log2012.log </span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ls -al log2012.log </span></div><div class="line">-rwxr-xr-x 1 root root 302108 11-13 06:03 log2012.log</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment">#</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;即设定文件log2012.log的属性为：文件属主（u） 增加执行权限；与文件属主同组用户（g） 增加执行权限；其他用户（o） 增加执行权限。</p>
<h3 id="实例2：同时修改不同用户权限"><a href="#实例2：同时修改不同用户权限" class="headerlink" title="实例2：同时修改不同用户权限"></a>实例2：同时修改不同用户权限</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">chmod  ug+w,o-x log2012.log</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ls -al log2012.log </span></div><div class="line">-rwxr-xr-x 1 root root 302108 11-13 06:03 log2012.log</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># chmod ug+w,o-x log2012.log </span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ls -al log2012.log </span></div><div class="line">-rwxrwxr-- 1 root root 302108 11-13 06:03 log2012.log</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;即设定文件log2012.log的属性为：文件属主（u） 增加写权限;与文件属主同组用户（g） 增加写权限;其他用户（o） 删除执行权限</p>
<h3 id="实例3：删除文件权限"><a href="#实例3：删除文件权限" class="headerlink" title="实例3：删除文件权限"></a>实例3：删除文件权限</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">chmod a-x log2012.log</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ls -al log2012.log </span></div><div class="line">-rwxrwxr-- 1 root root 302108 11-13 06:03 log2012.log</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># chmod a-x log2012.log </span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ls -al log2012.log </span></div><div class="line">-rw-rw-r-- 1 root root 302108 11-13 06:03 log2012.log</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;删除所有用户的可执行权限</p>
<h3 id="实例4：使用-“-”-设置权限"><a href="#实例4：使用-“-”-设置权限" class="headerlink" title="实例4：使用 “=” 设置权限"></a>实例4：使用 “=” 设置权限</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">chmod u=x log2012.log</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ls -al log2012.log </span></div><div class="line">-rw-rw-r-- 1 root root 302108 11-13 06:03 log2012.log</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># chmod u=x log2012.log </span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ls -al log2012.log </span></div><div class="line">---xrw-r-- 1 root root 302108 11-13 06:03 log2012.log</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;撤销原来所有的权限，然后使拥有者具有可读权限</p>
<h3 id="实例5：对一个目录及其子目录所有文件添加权限"><a href="#实例5：对一个目录及其子目录所有文件添加权限" class="headerlink" title="实例5：对一个目录及其子目录所有文件添加权限"></a>实例5：对一个目录及其子目录所有文件添加权限</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">chmod -R u+x test4</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cd test4</span></div><div class="line">[root@localhost test4]<span class="comment"># ls -al</span></div><div class="line">总计 312drwxrwxr-x 2 root root   4096 11-13 05:50 .</div><div class="line">drwxr-xr-x 5 root root   4096 11-22 06:58 ..</div><div class="line">-rw-r--r-- 1 root root 302108 11-12 22:54 log2012.log</div><div class="line">-rw-r--r-- 1 root root     61 11-12 22:54 log2013.log</div><div class="line">-rw-r--r-- 1 root root      0 11-12 22:54 log2014.log</div><div class="line">[root@localhost test4]<span class="comment"># cd ..</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># chmod -R u+x test4</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cd test4</span></div><div class="line">[root@localhost test4]<span class="comment"># ls -al</span></div><div class="line">总计 312drwxrwxr-x 2 root root   4096 11-13 05:50 .</div><div class="line">drwxr-xr-x 5 root root   4096 11-22 06:58 ..</div><div class="line">-rwxr--r-- 1 root root 302108 11-12 22:54 log2012.log</div><div class="line">-rwxr--r-- 1 root root     61 11-12 22:54 log2013.log</div><div class="line">-rwxr--r-- 1 root root      0 11-12 22:54 log2014.log</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;递归地给test4目录下所有文件和子目录的属主分配权限</p>
<h3 id="其他一些实例"><a href="#其他一些实例" class="headerlink" title="其他一些实例"></a>其他一些实例</h3><h4 id="1"><a href="#1" class="headerlink" title="1."></a>1.</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;命令</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">chmod 751 file</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;说明</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;给 file 的属主分配读、写、执行（7）的权限，给 file 的所在组分配读、执行（5）的权限，给其他用户分配执行（1）的权限</p>
<h4 id="2"><a href="#2" class="headerlink" title="2."></a>2.</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;命令</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">chmod u=rwx,g=rx,o=x file</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;说明</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;上例的另一种形式</p>
<h4 id="3"><a href="#3" class="headerlink" title="3."></a>3.</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;命令</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">chmod a=r file</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;说明</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;为所有用户分配读权限</p>
<h4 id="4"><a href="#4" class="headerlink" title="4."></a>4.</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;命令</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">chmod 444 file</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;说明</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;同上例</p>
<h4 id="5"><a href="#5" class="headerlink" title="5."></a>5.</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;命令</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">chmod a-wx,a+r file</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;说明</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;同上例</p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Linux命令/" rel="tag"># Linux命令</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/09/03/2. Linux 命令/9. Linux 命令- cp/" rel="next" title="Linux 命令- cp">
                <i class="fa fa-chevron-left"></i> Linux 命令- cp
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/09/03/2. Linux 命令/36. Linux 命令- du/" rel="prev" title="Linux 命令- du">
                Linux 命令- du <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/0.png"
               alt="失落的乐章" />
          <p class="site-author-name" itemprop="name">失落的乐章</p>
           
              <p class="site-description motion-element" itemprop="description">失落的乐章的Blog</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/">
                <span class="site-state-item-count">627</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">38</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/hcldirgit" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-命令格式"><span class="nav-number">1.</span> <span class="nav-text">1.命令格式</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-命令功能"><span class="nav-number">2.</span> <span class="nav-text">2.命令功能</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-命令参数"><span class="nav-number">3.</span> <span class="nav-text">3.命令参数</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#必要参数"><span class="nav-number">3.1.</span> <span class="nav-text">必要参数</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#选择参数"><span class="nav-number">3.2.</span> <span class="nav-text">选择参数</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#权限范围"><span class="nav-number">3.2.1.</span> <span class="nav-text">权限范围</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#权限代号"><span class="nav-number">3.2.2.</span> <span class="nav-text">权限代号</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#文字设定法"><span class="nav-number">3.2.2.1.</span> <span class="nav-text">文字设定法</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#数字设定法"><span class="nav-number">3.2.2.2.</span> <span class="nav-text">数字设定法</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#数字与字符对应关系如下"><span class="nav-number">3.2.2.2.1.</span> <span class="nav-text">数字与字符对应关系如下</span></a></li></ol></li></ol></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-使用实例"><span class="nav-number">4.</span> <span class="nav-text">4.使用实例</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#实例1：增加文件所有用户组可执行权限"><span class="nav-number">4.1.</span> <span class="nav-text">实例1：增加文件所有用户组可执行权限</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例2：同时修改不同用户权限"><span class="nav-number">4.2.</span> <span class="nav-text">实例2：同时修改不同用户权限</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例3：删除文件权限"><span class="nav-number">4.3.</span> <span class="nav-text">实例3：删除文件权限</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例4：使用-“-”-设置权限"><span class="nav-number">4.4.</span> <span class="nav-text">实例4：使用 “=” 设置权限</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例5：对一个目录及其子目录所有文件添加权限"><span class="nav-number">4.5.</span> <span class="nav-text">实例5：对一个目录及其子目录所有文件添加权限</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#其他一些实例"><span class="nav-number">4.6.</span> <span class="nav-text">其他一些实例</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1"><span class="nav-number">4.6.1.</span> <span class="nav-text">1.</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2"><span class="nav-number">4.6.2.</span> <span class="nav-text">2.</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3"><span class="nav-number">4.6.3.</span> <span class="nav-text">3.</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4"><span class="nav-number">4.6.4.</span> <span class="nav-text">4.</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#5"><span class="nav-number">4.6.5.</span> <span class="nav-text">5.</span></a></li></ol></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">失落的乐章</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.1"></script>



  


  




	





  





  





  






  





  

  

  

  

  

  

</body>
</html>
